﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace STRobot
{
    public partial class MonsterAddWnd : Form
    {
        public MonsterAddWnd()
        {
            InitializeComponent();
            index_ = -1;
        }

        int index_ { get; set; }
        public MonsterAddWnd(int index) //编辑
        {
            InitializeComponent();
            index_ = -1;
            if (index >= 0)
            {
                index_ = index;
                textBox1.Text = Config.Get().bigmonsterlist[index].tid.ToString();
                textBox2.Text = Config.Get().bigmonsterlist[index].name;
                textBox3.Text = Config.Get().bigmonsterlist[index].level.ToString();
                checkBox1.Checked = Config.Get().bigmonsterlist[index].type == 0 ? true : false;
                button1.Text = "修改";
            }
           
        }
        private void button1_Click(object sender, EventArgs e)
        {
            Bigmonster bigmonster = new Bigmonster();
            bigmonster.type = checkBox1.Checked ? 0 : 1; //0为排除 1为攻击
            bigmonster.tid = Convert.ToInt32(this.textBox1.Text);
            bigmonster.name = this.textBox2.Text;
            bigmonster.level = Convert.ToInt32(this.textBox3.Text);
            if (bigmonster.level == 0)
            {
                bigmonster.level = 2;
            }
            if (this.textBox1.Text.Length == 0 && textBox2.Text.Length == 0)
            {
                MessageBox.Show("tid和名称至少填一个");
                return;
            }


            if (index_ >= 0) //修改
            {
                Config.Get().bigmonsterlist[index_] = bigmonster;
            }
            else
            {
                foreach (var item in Config.Get().bigmonsterlist)
                {
                    if (item.tid != 0 && (item.tid == bigmonster.tid || item.name == bigmonster.name))
                    {
                        MessageBox.Show("已经存在此名称");
                        return;
                    }
                }
                Config.Get().bigmonsterlist.Add(bigmonster);
            }
            DialogResult = DialogResult.OK;
            Close();
        }
    }
}
